package cn.itcast.solr;

import org.apache.solr.client.solrj.SolrServer;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.impl.HttpSolrServer;
import org.junit.Test;

import java.io.IOException;

public class SolrIndexDelete {
    /**
     * @Description:通过id删除索引
     *
     * @Author:fsy
     * @Date:2018/3/2
     */
    @Test
    public void testDeleteIndexById() throws IOException, SolrServerException {
        //连接服务器
        SolrServer solrServer = new HttpSolrServer("http://localhost:8080/solr/core1");
        //根据id删除索引
        solrServer.deleteById("1");
        //提交
        solrServer.commit();
        System.out.println("删除索引完成");
    }

    /**
     * @Description:通过查询条件删除索引
     *
     * @Author:fsy
     * @Date:2018/3/2
     */
    @Test
    public void testDeleteIndexByQuery() throws IOException, SolrServerException {
        //连接服务器
        SolrServer solrServer = new HttpSolrServer("http://localhost:8080/solr/core1");
        //根据查询条件删除索引
        solrServer.deleteByQuery("title:");
        //提交
        solrServer.commit();
        System.out.println("根据查询条件删除索引完成");
    }
}
